package com.framework.service.yhbservice.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.YHBDao.transactionDao.YhbFlowTakeDao;
import com.framework.page.PageUtils;
import com.framework.service.yhbservice.YhbFlowTakeService;
import com.framework.service.yhbservice.YhbUserService;
import com.framework.yhbEntity.transaction.YhbFlowTake;
import com.framework.yhbEntity.user.YhbUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Transactional(rollbackFor = Exception.class)
@Service("yhbFlowTakeService")
public class YhbFlowTakeServiceImpl extends ServiceImpl<YhbFlowTakeDao,YhbFlowTake> implements YhbFlowTakeService {
    @Autowired
    private YhbUserService yhbUserService;

    @Override
    public List<YhbFlowTake> queryFlowTakeList(String token, Integer pageNo) {

        YhbUser user = yhbUserService.queryUserByToken(token);

        List<YhbFlowTake> list = baseMapper.selectPage(new Page<YhbFlowTake>(pageNo * 10, 10), new EntityWrapper<YhbFlowTake>()
                .eq("user_id", user.getUserId())
        );
        return list;
    }

    @Override
    public PageUtils queryFlowTakePage(Map<String, Object> params) {
        params.put("startTime", params.get("startTime"));
        params.put("endTime", params.get("endTime"));
        Integer currpage = Integer.valueOf(params.get("page").toString());
        Integer pageSize = Integer.valueOf(params.get("limit").toString());
        params.put("start", (currpage - 1) * pageSize);
        params.put("limit", pageSize);
        List<Map<String,Object>> list=baseMapper.queryFlowTakeList(params);
        Integer count=baseMapper.queryFlowTakeCount(params);
        return new PageUtils(list, count, pageSize, currpage);
    }


}
